Repository navigation
feat(formal): add Lean models of the charge intent and Tempo charge - #413
brendanjryan wants to merge 1 commit into
Conversation
…ith a shared core Adds formal/core (MppCore and the shared proof gate), formal/intent-charge and formal/tempo-charge, and a CI workflow that runs every model's check.sh with a pinned, checksummed Lean.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aec4ce9e45
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| | .hash t => | ||
| if cr.echo.request.push = true ∧ cr.echo.request.feePayer = false ∧ succeeded st t = true ∧ | ||
| Pays cfg cr.echo.request t.calls = true ∧ (cfg.txSingleUse = true → t ∉ st.consumedTx) then | ||
| some (settleTx st cr.echo.id t) |
There was a problem hiding this comment.
Model the required challenge-bound memo checks
For a push payment without methodDetails.memo, this branch accepts a transfer with no memo, including the observer's claim in Gap5_observer_claims_payment. However, the existing Tempo draft's “Memo Requirements by Credential Type” and “Hash Verification” sections require the primary transfer to carry an attribution memo matching the challenge and require rejection otherwise. They also prohibit hash credentials whenever methodDetails.memo is present, which this branch likewise permits. Consequently, the guarded model accepts credentials the draft forbids and reports a payment-theft counterexample already prevented by the specification. Model the credential-specific memo checks and update the affected witnesses and gap claims.
AGENTS.md reference: AGENTS.md:L71-L71
Useful? React with 👍 / 👎.
|
|
||
| | # | Where | Gap | Guard (`Cfg`) | Breaks | Counterexample | | ||
| |---|---|---|---|---|---| | ||
| | 1 | §Hash Verification; core §Replay Protection, §Concurrent Request Handling | A spent transaction's hash is not refused again: one payment settles a pull challenge and a hash challenge with the same request, after the pull settles or in the window between its broadcast and its settlement | `txSingleUse` | P3 | `G1_violates_P3`, `G1_guard_rejects`, `G1_race_window`, `G1_race_violates_P3`, `G1_race_guard_rejects` | |
There was a problem hiding this comment.
Treat the accepted-transfer record as an existing requirement
Row 1 describes transaction reuse as a missing draft rule, but specs/methods/tempo/draft-tempo-charge-00.md already mandates a shared accepted-transfer record for pull and push, rejection of already-counted transfers, and recording before returning a receipt (“Hash Verification” and “Accepted-Transfer Record”, lines 917–949). It explicitly permits the transaction-hash-only policy used by this model. Turning off txSingleUse therefore demonstrates a noncompliant implementation, not the claimed specification omission. Reclassify this guard and its counterexamples as enforcement of an existing requirement rather than publishing them as an unresolved draft gap.
AGENTS.md reference: AGENTS.md:L71-L71
Useful? React with 👍 / 👎.
Spec Preview
|
There was a problem hiding this comment.
Beyond the inline finding, I also checked the CI supply chain in .github/workflows/formal.yml. The actions are pinned by SHA, the elan and Lean downloads are checked against SHA-256 before they're unpacked, every lean-toolchain must match the pinned version so elan never fetches an unchecked toolchain, and checkout runs with persist-credentials: false. I found no problem there. I didn't run the Lean builds or the check.sh gates myself.
Extended reasoning...
The workflow installs pinned, checksum-verified tools and runs repo scripts with only contents:read plus the id-token permission the secure-runner step uses. Nothing in that path was found to be exploitable.
| | .hash t => | ||
| if cr.echo.request.push = true ∧ cr.echo.request.feePayer = false ∧ succeeded st t = true ∧ | ||
| Pays cfg cr.echo.request t.calls = true ∧ (cfg.txSingleUse = true → t ∉ st.consumedTx) then | ||
| some (settleTx st cr.echo.id t) | ||
| else none |
There was a problem hiding this comment.
🔴 The Tempo model checks hash credentials against an older draft than the one in this repo, so GAPS.md reports open spec gaps the draft already closes. The .hash branch accepts a transfer with any memo or none. The draft instead requires the expected attribution memo, rejects hash credentials when methodDetails.memo is set, and keeps an accepted-transfer record. Fix: add the memo rules and the shared record to Request/Transfer and the .hash and .transaction guards, then re-derive GAPS rows 1, 5 and 7 so each row describes the current text.
Why this was flagged
specs/methods/tempo/draft-tempo-charge-00.md is not changed by this PR. Its §Memo Requirements (lines 274-284) says servers MUST reject a hash credential with verification-failed when no primary transfer carries the expected memo, i.e. an attribution memo bound to this challenge id. Its §Hash Verification and §Accepted-Transfer Record (lines 909-949) say a transfer already counted for any challenge does not count again, and pull transfers go into the same record. Model.lean:339-343 checks only push, feePayer, succeeded, Pays and the G1 flag. Request has no memo-mode or attribution field, so with Cfg.Guarded the model still accepts an observer's hash claim. As a result Gap5_observer_claims_payment (Counterexamples.lean:159) proves an attack a conforming server rejects. GAPS.md:11/18 says "the draft requires neither", and Model.lean:146 and GAPS row 1 call §Hash Verification "silent", which lines 917-921 contradict. The base branch had no model, so it made no such claims.
Verification: In formal/tempo-charge/TempoCharge/Model.lean:339-343, the .hash branch checks only push, feePayer, succeeded, Pays and the G1 flag. So with methodDetails.memo absent, a hash transfer with any memo or no memo is accepted. The spec is not in the PR's diff, and the base copy already contains the rules the model leaves out.
Adds Lean 4 models of two MPP drafts, with a shared core and a CI job that checks them.
formal/core: sharedMppCore(state machine harnessrun/Reachable, map updatesupd) and the proof gate every model runs (check-lib.sh,Audit.lean): clean build withwarningAsError, noset_option,import Leanor metaprogramming, and an axiom audit with kernel replay that rules outsorry,admitandnative_decide.formal/intent-charge: the core scheme with the charge intent (draft-httpauth-payment-01, draft-payment-intent-charge-00): proofs of its properties for every reachable state, witnesses, and a counterexample per rule the draft leaves out (GAPS.md).formal/tempo-charge: draft-tempo-charge-00 (pull, push and zero-amount proof credentials, fee sponsorship, splits, expiry, replay rules, receipts) on top of the charge intent, with the same structure..github/workflows/formal.yml: installs elan and the Lean release pinned by version and SHA-256, then runs everyformal/*/check.sh.formal/README.mdandAGENTS.md: how to run a model and when to update one.This is split out of #402 so the shared core and the charge models can land first; the Tempo session model (#400) follows later on top of it.
Checks
With elan v4.2.4 and Lean 4.35.0 installed and checksummed as
formal.ymldoes:bash formal/core/check.sh: OK (7 theorems, standard axioms only, kernel replay passed)bash formal/intent-charge/check.sh: OK (163 theorems)bash formal/tempo-charge/check.sh: OK (240 theorems)actionlint .github/workflows/formal.yml: cleanSplit out of #402 with AI assistance (Pyramid).